import Vue from 'vue'
import Router from 'vue-router'
// import { component } from 'vue/types/umd'
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)

const Home =()=> import("../views/home/Home")
const Cart = ()=>import("../views/cart/Cart")
const Category=()=>import("../views/category/Category")
const Me =()=>import("../views/me/Me")

const routes = [
  {
    path:'',
    redirect:"/home"
  },
  {
    path:'/home',
    component: Home
  },
  {
    path:'/cart',
    component: Cart
  },
  {
    path:'/category',
    component: Category
  },
  {
    path:'/me',
    component: Me
  }
]

const router = new Router({
  routes,
  mode:'history',
  // linkActiveClass:'active'
})

// 前置钩子
router.beforeEach((to,from,next)=>{
  // document.title = to.matched[0].meta.title;
  next();
})

// router.afterEach((to,from)=>{
//
// })

export default router
